//
//  ReleaseDynamicViewController.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/12.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "ReleaseDynamicViewController.h"
#import "ReleaseDynamicViewModel.h"
#import "StellCaiculatorCollectionViewCell.h"
#import "ZZPhotoController.h"

@interface ReleaseDynamicViewController ()
@property (nonatomic, strong) ReleaseDynamicViewModel *viewModel;
@end

@implementation ReleaseDynamicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发动态";
    [self addNavigationItemWithImageNames:@[@"goods_share"] isLeft:YES target:self action:@selector(leftAction:) tags:@[@002]];
    [self addNavigationItemWithTitles:@[@"发布"] isLeft:NO target:self action:@selector(rightAction:) tags:@[@122] theButTitColor:[UIColor colorWithHexString:@"#A89A60"] titFont:SYSTEMFONT(14)];
    self.viewModel = [[ReleaseDynamicViewModel alloc] initWithViewToViewCollectionView:self.collectionView theFlowLayout:self.flow theSuperView:self.view];
    kWeakSelf(self);
    self.viewModel.BlockChoosePhones = ^(NSInteger row) {
        [weakself choosePhonesRow:row];
    };
    self.viewModel.BlockPluseDone = ^{
        [weakself plusDone];
    };
}

- (void)choosePhonesRow:(NSInteger)row
{
    if (row == 1) { // 相册
        NSInteger maxNum = 9;
        NSInteger num = maxNum - self.viewModel.cout;
        ZZPhotoController *photoController = [[ZZPhotoController alloc] init];
        photoController.selectPhotoOfMax = num;
        photoController.roundColor = [UIColor clearColor];
        kWeakSelf(self);
        [photoController showIn:self result:^(id responseObject){
            [weakself takePhoneWith:responseObject];
        }];
    } else { // 相机
    }
}

- (void)leftAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)rightAction:(UIButton *)sender
{
    [self.viewModel plus];
}

- (void)takePhoneWith:(id)res
{
    if (self.viewModel.arr.count > 0) {
        [self.viewModel.arr removeAllObjects];
        self.viewModel.arr = nil;
    }
    self.viewModel.arr = [NSMutableArray arrayWithArray:res];
}

- (void)plusDone
{
    // 发布完成需要做的事情：或许还需要刷新一下前一个页面
    [self.navigationController popViewControllerAnimated:YES];
}

@end
